#include <common.h>

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspthreadman.h>
#include <psploadexec.h>
#include <pspumd.h>
#include <pspiofilemgr.h>

char data1[420];
char data2[420];

unsigned char data3[420] = 
{
	0x00,0x50,0x53,0x46,0x01,0x01,0x00,0x00,0x94,0x00,0x00,0x00,0xE8,0x00,0x00,
	0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x00,0x00,0x00,0x04,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x00,0x04,0x02,0x03,0x00,0x00,0x00,0x04,
	0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x00,0x04,0x02,0x0A,0x00,0x00,0x00,
	0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x1A,0x00,0x04,0x02,0x05,0x00,0x00,
	0x00,0x08,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x27,0x00,0x04,0x04,0x04,0x00,
	0x00,0x00,0x04,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x36,0x00,0x04,0x02,0x05,
	0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x45,0x00,0x04,0x04,
	0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,0x4C,0x00,0x04,
	0x02,0x10,0x00,0x00,0x00,0x89,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x42,0x4F,
	0x4F,0x54,0x41,0x42,0x4C,0x45,0x00,0x43,0x41,0x54,0x45,0x47,0x4F,0x52,0x59,
	0x00,0x44,0x49,0x53,0x43,0x5F,0x49,0x44,0x00,0x44,0x49,0x53,0x43,0x5F,0x56,
	0x45,0x52,0x53,0x49,0x4F,0x4E,0x00,0x50,0x41,0x52,0x45,0x4E,0x54,0x41,0x4C,
	0x5F,0x4C,0x45,0x56,0x45,0x4C,0x00,0x50,0x53,0x50,0x5F,0x53,0x59,0x53,0x54,
	0x45,0x4D,0x5F,0x56,0x45,0x52,0x00,0x52,0x45,0x47,0x49,0x4F,0x4E,0x00,0x54,
	0x49,0x54,0x4C,0x45,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x4D,0x47,0x00,0x00,
	0x55,0x43,0x4A,0x53,0x31,0x30,0x30,0x34,0x31,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x31,0x2E,0x30,0x30,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x31,0x2E,
	0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x52,0x41,0x57,0x20,0x41,
	0x43,0x43,0x45,0x53,0x53,0x20,0x54,0x45,0x53,0x54,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00
};


#define FILE_NAME "disc0:/PSP_GAME/PARAM.SFO"

int main(int argc, char **argv)
{
	char temp[1024];
	SceIoStat sceIoStat;
	int fileHandle;

	printf("sceIoGetstat: %d\n", sceIoGetstat(FILE_NAME, &sceIoStat));
	printf("Size: %lld\n", sceIoStat.st_size);
	printf("LBN: %d\n", sceIoStat.st_private[0]);
	{
		fileHandle = sceIoOpen(FILE_NAME, PSP_O_RDONLY, 0777);
		printf("HandleNormal: %s\n", (fileHandle > 0) ? "Ok" : "Error");
		sceIoRead(fileHandle, data2, sizeof(data2));
		sceIoClose(fileHandle);
		printf("memcmp_Normal: %d\n", memcmp(data2, data3, sizeof(data3)));
	}
	{
		sprintf(temp, "disc0:/sce_lbn0x%08X_size0x%08X", (int)sceIoStat.st_private[0], (int)sceIoStat.st_size);
		fileHandle = sceIoOpen(temp, PSP_O_RDONLY, 0777);
		printf("HandleRaw: %s\n", (fileHandle > 0) ? "Ok" : "Error");
		sceIoRead(fileHandle, data1, sizeof(data1));
		sceIoClose(fileHandle);
		printf("memcmp_Raw: %d\n", memcmp(data1, data3, sizeof(data3)));
	}

	return 0;
}